﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Homework_1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            /*
             * 操作数组的函数
             */
            button3.Text = "";
            if (richTextBox1.Text != "")
            {
                string[] strArr = richTextBox1.Text.Split(' ');
                int[] intArr = Array.ConvertAll(strArr, int.Parse);
                int min = intArr[0], max = intArr[0], ave = 0, plus = 0;
                foreach (int tmp in intArr)
                {
                    plus += tmp;
                    if (tmp >= max) max = tmp;
                    if (tmp < min) min = tmp;
                }
                ave = plus / intArr.Length;
                button3.Text = "\n最小值是" + min + "\n\n最大值是" + max + "\n\n平均值是" + ave + "\n\n总和是" + plus;
            }
            else button3.Text = "请先输入数值！";
        }

        private void button2_Click(object sender, EventArgs e)
        {
            /*
             * 打印素数的函数
             */
            button3.Text = "";
            if (textBox1.Text!=""&&textBox2.Text!="")
            {
                int min = int.Parse(textBox1.Text);
                int max = int.Parse(textBox2.Text);
                int lineNum = 0;
                for (int i = min+1; i < max; i++)
                {
                    bool isPri = true;
                    for (int j = 2; j < i; j++)
                    {
                        if (i % j == 0) isPri = false;
                    }
                    if (isPri)
                    {
                        button3.Text += i + " ";
                        lineNum++;
                    }
                    if (lineNum==10)
                    {
                        lineNum = 0;
                        button3.Text += "\n";
                    }
                }
            }
            else button3.Text = "请先输入数值！";
        }
    }
}
